package org.ithasu.tools.data.impl;

import java.util.HashMap;
import java.util.Map;

import org.ithasu.tools.data.EntityProvider;
import org.ithasu.tools.net.JSONTools.JSONContext;

public class DefaultJSONContext implements JSONContext {

	private final HashMap<String, EntityProvider<?>> providers = new HashMap<String, EntityProvider<?>>();

	public final void register(String name, EntityProvider<?> provider) {
		providers.put(name, provider);
	}

	public void clear() {
		providers.clear();
	}

	@Override
	public EntityProvider<?> getEntityProvider(String name) {
		return providers.get(name);
	}

	@Override
	public String getEntityProviderId(EntityProvider<?> provider) {
		for (Map.Entry<String, EntityProvider<?>> e : providers.entrySet()) {
			if (e.getValue() == provider) {
				return e.getKey();
			}
		}
		return null;
	}

}
